//
//  HWGameDetailWelfareCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/3/15.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWGameDetailWelfareCell: UITableViewCell {
    var bgImageView:UIImageView!
    var titleLabel:UILabel!
    var model:HWGameDetailInfoModel? {
        didSet {
            if (model?.fuli.count ?? 0) > 0 {
                bgImageView.isHidden = true
                titleLabel.text = model?.fuli
                titleLabel.textColor = .colorWithHexString(hexString: "#888888")
                bgImageView.snp.remakeConstraints { make in
                    
                }
                titleLabel.snp.remakeConstraints { make in
                    make.left.top.equalTo(15*widthScale)
                    make.right.equalTo(-15*widthScale)
                    make.bottom.equalTo(-30*widthScale)
                }
            } else {
                bgImageView.isHidden = false
                titleLabel.textColor = .colorWithHexString(hexString: "#333333")
                bgImageView.snp.remakeConstraints { make in
                    make.left.top.equalTo(15*widthScale).priority(.high)
                    make.right.equalTo(-15*widthScale)
                    make.height.equalTo(75*widthScale)
                    make.bottom.equalTo(-30*widthScale)
                }
                
                titleLabel.snp.remakeConstraints { make in
                    make.centerY.equalTo(bgImageView)
                    make.left.equalTo(25*widthScale)
                    make.right.equalTo(-25*widthScale)
                }
            }
        }
    }
    class func cellWithTableView(tableView:UITableView) -> (HWGameDetailWelfareCell) {
        let reUse:String = "HWGameDetailWelfareCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWGameDetailWelfareCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWGameDetailWelfareCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        bgImageView = UIImageView()
        bgImageView.image = UIImage(named: "gameDetailWelfareBg")
        bgImageView.contentMode = .scaleAspectFill
        contentView.addSubview(bgImageView)
        
        titleLabel = HWLabel.createLabel(title: "暂无福利活动，敬请期待！", color: "#333333", font: 14*widthScale)
        contentView.addSubview(titleLabel)
    }
    
    func initFrame() -> Void {
        bgImageView.snp.makeConstraints { make in
            make.left.top.equalTo(15*widthScale)
            make.right.equalTo(-15*widthScale)
            make.height.equalTo(75*widthScale)
            make.bottom.equalTo(-30*widthScale)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(bgImageView)
            make.left.equalTo(25*widthScale)
            make.right.equalTo(-25*widthScale)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
